%% Rednoise CGI simulation (for DL training)
% please load the file rednoise1.2f_10000.mat first
% load('/Users/niexiaoyu/Desktop/RESEARCH9_DeepLearning/MatLab程序');
target=double(rgb2gray(imread('/Users/niexiaoyu/Desktop/RESEARCH9_DeepLearning/target/S_size400.png')));
sizex=54;
sizey=98;
Npixel=sizex*sizey;
b=0.011; %beta
target=imresize(target,[sizex,sizey]);
target(target<255)=0;
Nth=round(Npixel*b);
PI=zeros(sizex,sizey);
P=zeros(sizex,sizey);
I=[];
for i=1:1:Nth
    pass=target.*eval(['txt',num2str(i)]);
    I(i)=sum(pass(:));
    P=P+eval(['txt',num2str(i)]);
    PI=PI+eval(['I(',num2str(i),').*txt',num2str(i)]);
end
PI_mean=PI/Nth;
P_mean=P/Nth;
I_mean=sum(I(:))/Nth;
result=PI_mean./(P_mean*I_mean)-1;
% subplot(1,2,1);
% imshow(target,[]);
% colorbar('LineWidth',1.5);
% set(gca,'FontName','Times New Roman','FontSize',25,'LineWidth',1.5);
% subplot(1,2,2);
imagesc(result);
% Npixel=sum(target(:))/255;
b=Nth/Npixel;
title(['\beta',' = ',num2str(b)]);
colorbar('LineWidth',1.5);
set(gca,'FontName','Times New Roman','FontSize',25,'LineWidth',1.5);










